/**
 * Company : SIANGKLOM.
 * Created By : Chatree Siangklom
 * Created On : Sep 26, 2013  11:06:06 AM 
 * e-Mail : dr_chatree@hotmail.com
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : com.tis.database.dao.security.impl
 * File Name : AdUserLoginHistoryDaoImpl.java
 * TODO
 */
package com.tis.database.dao.security.impl;

import java.math.BigDecimal;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.annotations.Synchronize;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.tis.database.dao.impl.AbstractDaoImpl;
import com.tis.database.dao.security.AdUserLoginHistoryDao;
import com.tis.database.entitys.security.AdUserLoginHistory;

/**
 * @author Chatree Siangklom of Administrator
 * Date =Sep 26, 2013 : 11:06:06 AM 
 * CreateBy=Chatree Siangklom
 * TODO
 */
@Repository
@SuppressWarnings("unchecked")
public class AdUserLoginHistoryDaoImpl extends AbstractDaoImpl<AdUserLoginHistory, BigDecimal> implements AdUserLoginHistoryDao {

	private static final Logger logging = LoggerFactory.getLogger(AdUserLoginHistoryDaoImpl.class);
	/**
	 * Date =Sep 26, 2013 : 11:07:14 AM 
	 * CreateBy=Chatree Siangklom
	 * TODO
	 * @param entityClass
	 */
	protected AdUserLoginHistoryDaoImpl() {
		super(AdUserLoginHistory.class);
	}

	/** (Javadoc)
	 * @see com.tis.database.dao.impl.AbstractDaoImpl#save(java.lang.Object)
	 * Date =Sep 26, 2013 : 11:08:22 AM 
	 * CreateBy=Chatree Siangklom
	 * TODO
	 */
	@Override
	public void save(AdUserLoginHistory e) throws HibernateException {
		Session session = getCurrentSession();
		Transaction tx = session.getTransaction();
		try {
			
			tx.begin();
			session.save(e);
			try {
		        tx.commit();
		        while (!tx.wasCommitted())
;
		    }catch(Exception exx){
		    	exx.printStackTrace();
		    }
		}catch(HibernateException ex) {
			tx.rollback();
			ex.printStackTrace();
			throw ex;
		}finally {
			session.flush();
			//session.close();
		}
	}
	
	/** (Javadoc)
	 * @see com.tis.database.dao.impl.AbstractDaoImpl#delete(java.lang.Object)
	 * Date =Sep 26, 2013 : 11:31:32 AM 
	 * CreateBy=Chatree Siangklom
	 * TODO
	 */
	@Override
	public void delete(AdUserLoginHistory e) throws HibernateException {
		// TODO Auto-generated method stub
		super.delete(e);
	}
	
	/** (Javadoc)
	 * @see com.tis.database.dao.impl.AbstractDaoImpl#saveOrUpdate(java.lang.Object)
	 * Date =Sep 26, 2013 : 11:32:05 AM 
	 * CreateBy=Chatree Siangklom
	 * TODO
	 */
	@Override
	public void saveOrUpdate(AdUserLoginHistory e) throws HibernateException {

		super.saveOrUpdate(e);
	}
	
	/** (Javadoc)
	 * @see com.tis.database.dao.impl.AbstractDaoImpl#NextSequence(java.lang.String)
	 * Date =Sep 26, 2013 : 1:10:19 PM 
	 * CreateBy=Chatree Siangklom
	 * TODO
	 */
	@Override	
	synchronized
	public BigDecimal NextSequence(String name) throws HibernateException, Exception {
		return super.NextSequence(name);
	}

	/** (Javadoc)
	 * @see com.tis.database.dao.security.AdUserLoginHistoryDao#NextSequence()
	 * Date =Oct 16, 2013 : 4:13:20 PM 
	 * CreateBy=Chatree Siangklom
	 * TODO
	 */
	@Override
	public BigDecimal NextSequence() throws HibernateException, Exception {
		
		return super.NextSequence("AD_USER_LOGIN_HISTORY");
	}
}
